home *** CD-ROM | disk | FTP | other *** search
- Path: panoramix.fi.upm.es!dia!sacha
- From: sacha@diafi.upm.es (Sacha)
- Newsgroups: comp.lang.c++
- Subject: another overloading question
- Date: 3 Apr 1996 16:33:17 GMT
- Organization: CS Dept., Technical University of Madrid
- Sender: sacha@dia (Sacha)
- Distribution: world
- Message-ID: <4ju98d$3al@panoramix.fi.upm.es>
- NNTP-Posting-Host: alba.dia.fi.upm.es
-
-
- Hi,
-
- Can I overload = for simple types?
-
-
- I mean, if for example I have:
-
- class Colour
- {
- private:
- float r_, g_, b_;
-
- public:
- Colour(float r, float g, float b)
- {r_=r; g_=g; b_=b;}
- };
-
- is there some way I can overload = so that I can do things like:
-
- Colour colour(0.99238, 0.172364, 0.273);
-
- int intensity = colour;
-
-
- such that intensity is assigned a value computed from r,g,b (e.g. the average)?
-
-
- I think someone else may have asked this, phrasing it all with lvalues and
- rvalues, but I lost the thread.
-
- I suspect that the compiler treats simple types at compile time and there may be
- no way to do this. I suppose I can substitute it with a normal member function...
-
- Any help much appreciated...
-
- Sacha.
-
-
-
- --
- "It's not just pork, Gilbert, it's power."
-